<template>
  <div style="padding: 10px; width: 100%">
    <div style="margin: 10px 0">
      <!-- <span class="a1">年级：</span>
      <el-select v-model="value" placeholder="请选择" style="width: 130px">
        <el-option
          v-for="item in options"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        >
        </el-option>
      </el-select>
      <span class="a1">班级：</span>
      <el-select v-model="value" placeholder="请选择" style="width: 130px">
        <el-option
          v-for="item in options"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        >
        </el-option>
      </el-select> -->
    </div>
    <el-table :data="tableData" border stripe style="width: 99%" height="76vh">
      <el-table-column type="selection" width="55" />
      <el-table-column prop="id" label="ID" />
      <el-table-column prop="name" label="考试名称" />
      <el-table-column prop="time" label="考试时间" />
      <el-table-column prop="type" label="考试类型" />
      <el-table-column prop="gradeName" label="考试年级" />
      <el-table-column prop="remark" label="备注" :show-overflow-tooltip="true"/>

      <el-table-column label="操作" width="160px">
        <template #default="scope">
          <el-button
            @click="handleEdit(scope.row)"
            size="mini"
            type="primary"
            plain
            >录入成绩</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-dialog
      :title="title"
      v-model="courseVisible"
      width="50%"
      :before-close="dialogClose"
    >
    <el-table :data="courseInfo[0].clazzList" border stripe style="width: 100%">
      <el-table-column prop="name" label="班级" />
      <el-table-column label="操作" width="160px">
        <template #default="scope">
          <el-button
            @click="enterEdit(scope.row)"
            size="mini"
            type="primary"
            plain
            >进入</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    </el-dialog>
    <div style="margin: 10px 0">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import request from "../../utils/request";

export default {
  name: "Index",
  data() {
    return {
      courseVisible:false,
      //当前页
      currentPage: 1,
      pageSize: 10,
      total: 0,
      tableData: [],
      form: {},
      courseInfo:[]
    };
  },
  created() {
    //获取登录用户的缓存信息
    let str = sessionStorage.getItem("user") || "{}";
    this.form = JSON.parse(str);
    this.load();
    this.findCourse();
  },
  methods: {
    // 考试状态显示或隐藏考试列表
    handleEdit(row) {
      this.courseVisible = true;
      console.log("考试信息");
      console.log(row);
      sessionStorage.setItem("examInfo", JSON.stringify(row)); // 缓存考试信息
      // this.$router.push("/teacherscorelist"); //跳转到成绩页面
    },
    enterEdit: function(row){
      console.log("课程信息");
      console.log(row);
      // 班级id
      console.log(row.id);
      // 年级id
      console.log(row.gradeList.id);
      // 课程Id
      console.log(row.gradeList.courseList[0].id);
      sessionStorage.setItem("courseInfo", JSON.stringify(row)); // 缓存考试信息
      this.$router.push("/teacherscorelist"); //跳转到成绩页面
    },
    // 查询考试信息
    load() {
      console.log("111111111");
      console.log(this.form.account);
      request
        .get("/teacher/examlist", {
          params: {
            PageNum: this.currentPage,
            PageSize: this.pageSize,
            teacherId: this.form.account,
          },
        })
        .then((res) => {
          console.log("考试信息");
          console.log(res);
          console.log(res.data.records.length);
          this.tableData = res.data.records;
          this.total = res.data.total;
          for (let i = 0; i <= res.data.records.length; i++) {
            this.tableData[i].gradeName = res.data.records[i].gradeList.name
            if (res.data.records[i].type == 1) {
              this.tableData[i].type = "年级考试";
            } else {
              this.tableData[i].type = "平时考试";
            }
          }
        });
    },
    // 查询老师对应的年级班级课程
    findCourse() {
      console.log("教工号");
      request
        .get("/teacher/findBytId", {
          params: {
            tId: this.form.account,
          },
        })
        .then((res) => {
          console.log("老师课程信息");
          console.log(res);
          this.courseInfo = res.data
          console.log(this.courseInfo);
        });
    },

    //改变当前每页的个数触发
    handleSizeChange(pageSize) {
      this.pageSize = pageSize;
      this.load();
    },
    //改变当前页码触发
    handleCurrentChange(pageNum) {
      this.currentPage = pageNum;
      this.load();
    },
  },
};
</script>

<style>
.a1 {
  font-size: 12px;
  text-align: center;
  margin-left: 20px;
}
</style>

